package service

import (
	"AiBus/global"
	"AiBus/model"
	"AiBus/request"
	"AiBus/utils"
	"fmt"
	"github.com/gin-gonic/gin"
	"time"
)

func GetAllSystem(c *gin.Context, UserID string) {
	system := []model.SystemParameter{}
	var Count int64
	tx := global.App.DB.Where("user_id=?", UserID).Find(&system).Count(&Count)
	fmt.Println(system)
	if tx.Error != nil || tx.RowsAffected == 0 {
		global.App.Log.Error(tx.Error.Error())
		utils.Fail(c, 4100, "系统配置加载出错!!!")
	} else {
		tmp := []request.SystemParameterResp{}
		for _, item := range system {
			tmp = append(tmp, request.SystemParameterResp{
				ID:        item.ID,
				Email:     item.Email,
				CreatedAT: item.CreatedAt.Format(time.DateTime),
				UpdatedAT: item.UpdatedAt.Format(time.DateTime),
				UserID:    item.UserID,
			})

		}
		utils.Success(c, Count, tmp)
	}
}
